package com.lzc.ai.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;

/**
 * @author lizhichuan
 * @description: TODO
 * @date 2025/5/25 00:33
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class GameController {

    private final ChatClient gameChatClient;

    /**
     * 哄哄模拟器
     *
     * @param prompt
     * @param chatId
     * @return
     */
    @RequestMapping(value = "/game", produces = "text/html;charset=utf-8")
//    @GetMapping(value = "/game",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chat(String prompt, String chatId) {
        return gameChatClient.prompt()
                .user(prompt)
                .advisors(a -> a.param(CHAT_MEMORY_CONVERSATION_ID_KEY, chatId)) //添加会话id到AdvisorContext
                .stream()
                .content();
    }
}
